<include file="Common/header" />
<title>账单列表</title>
</head>
<body>
<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 账单管理 
	<span class="c-gray en">&gt;</span> 账单列表 
	<a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
		<i class="Hui-iconfont">&#xe68f;</i>
	</a>
</nav>
<div class="pd-20">
	<div class="codeView docs-example" data-afterContent="生成账单">
		<table class="table table-border table-bordered table-striped">
			<tbody>
				<tr>
					<td class="text-c" bgcolor="#f1f1f1" width="10%">费用年：</td>
					<td style="background-color: white;" width="10%">
						<span class="select-box radius">
							<select class="select" size="1" name="years" id="years">
								<?php $year = date('Y'); for($i= $year;$i>=($year-5);$i--){ ?>
								<option value="{$i}" {$i == date('m') ? 'selected' : ''}>{$i}年</option>
								<?php } ?>
							</select>
						</span>
					</td>
					
					<td class="text-c" bgcolor="#f1f1f1" width="10%">费用月：</td>
					<td style="background-color: white;" width="10%">
						<span class="select-box radius">
							<select class="select" size="1" name="months" id="months">
								<?php for($i=1;$i<=12;$i++){ ?>
								<option value="{$i}" {$i == date('m') ? 'selected' : ''}>{$i}月</option>
								<?php } ?>
							</select>
						</span>
					</td>
					
					<td class="text-c" bgcolor="#f1f1f1" width="7%">是否覆盖：</td>
					<td style="background-color: white;" width="17%">
						<div class="skin-minimal">
							<div class="radio-box">
								<input type="radio" id="radio-1" name="demo-radio1" value="1" />
								<label for="radio-1">是</label>
							</div>
							<div class="radio-box">
								<input type="radio" id="radio-2" name="demo-radio1" value="0" checked>
								<label for="radio-2">否</label>
							</div>
						</div>
					</td>
					
					<td style="background-color: white;">
						<a class="btn btn-primary radius order" istype="1" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 固定账单生成</a>
						<a class="btn btn-primary radius order" istype="2" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 日常账单生成</a>
					</td>
				</tr>
			</tbody>
		</table>
	</div>

	<div class="codeView docs-example" data-afterContent="按条件查询">
		<div style="padding-left: 20px;padding-right: 20px">
			<span style="display: inline-block;width: 250px;text-align: right">
				房间编号：
				<input class="input-text radius" id="room_number" name="room_number" style="width:150px" />
			</span>

			<span style="display: inline-block;width: 200px;text-align: right">
				账单类型：
				<span class="select-box radius" style="width: 100px">
					<select class="select" size="1" name="order_type" id="order_type">
						<option value="0">全部</option>
						<option value="1">固定</option>
						<option value="2">日常</option>
					</select>
				</span>
			</span>

			<span style="display: inline-block;width: 200px;text-align: right">
				账单状态：
				<span class="select-box radius" style="width: 100px">
					<select class="select" size="1" name="status" id="status">
						<option value="all">全部</option>
						<option value="-1">未审核</option>
						<option value="0">未结清</option>
						<option value="1">已交费</option>
						<option value="2">无效</option>
					</select>
				</span>
			</span>
			
			<span style="display: inline-block;width: 280px;text-align: right;margin-left: 13px;">
				收费月份：
				<span class="select-box radius" style="width: 100px;">
					<select class="select" size="1" name="qorder_year" id="qorder_year">
						<?php $year = date('Y'); for($i=$year;$i>=($year-5);$i--){ ?>
						<?php if($i == date('Y')){ ?>
						<option value="{$i}" selected="selected">{$i}年</option>
						<?php }else{ ?>
						<option value="{$i}">{$i}年</option>
						<?php } ?>
						<?php } ?>
					</select>
				</span>
				
				<span class="select-box radius" style="width: 100px;">
					<select class="select" size="1" name="qorder_type" id="qorder_type">
						<?php for($i=1;$i<=12;$i++){ ?>
						<?php if($i == date('m')){ ?>
						<option value="{$i}" selected="selected">{$i}月</option>
						<?php }else{ ?>
						<option value="{$i}">{$i}月</option>
						<?php } ?>
						<?php } ?>
					</select>
				</span>
			</span>
			
			<a href="javascript:;" class="btn btn-success radius querys"><i class="Hui-iconfont">&#xe709;</i> 查询</a> 
		</div>
	</div>
	
	<div class="cl pd-5 bg-1 bk-gray"> 
		<span class="l">
			审核状态选择：
			<span class="select-box radius" style="width: 100px;">
				<select class="select" size="1" name="allstatus" id="allstatus">
					<option value="0" selected="selected">通过</option>
					<option value="2">无效</option>
				</select>
			</span>
			<a class="btn btn-secondary radius report" href="javascript:;"><i class="Hui-iconfont">&#xe6e1;</i> 账单审核</a>
			<a class="btn btn-danger radius explodes" href="javascript:;"><i class="Hui-iconfont">&#xe644;</i> 导出账单</a>
		</span>
	</div>
	<input type="hidden" name="page" id="page" value="{$page}" />
	<div class="dataTables_wrapper no-footer" id="ajaxDiv">
		<include file="Costlog/list" />
	</div>
</div>

<script type="text/javascript">
	$(function(){
		$(".time").on('click', function(){
			laydate({istime: true, format: 'YYYY-MM-DD'});
		});
		
		//按条件查询
		$(".querys").on('click', function(){
			var load = layer.load(2);
			var where = {};
				where.room_number = $("#room_number").val();
				where.order_type = $("#order_type").val();
				where.status = $("#status").val();
				where.qorder_type = $("#qorder_type").val();
				where.qorder_year = $("#qorder_year").val();
				where.ajax = 1;
			$.get('index.html', where, function(data){
				layer.close(load);
				$("#ajaxDiv").html(data);
			});
		});

		//生成账单
		$(".order").on('click', function(){
			var load = layer.load(2);
			var istype = $(this).attr('istype');
			var months = $("#months").val();
			var years = $("#years").val();
			//判断是否覆盖
			var cover = $('input:radio[name="demo-radio1"]:checked').val();
			
			$.post('index.html', {year: years, month: months, istype: istype, cover: cover}, function(row){
				layer.close(load);
				
				if(row){
					layer.msg('账单生成成功', {icon: 1, time: 2000}, function(){
						//location.reload();
						//请求数据
						var where = {};
							where.room_number = $("#room_number").val();
							where.order_type = istype;
							where.qorder_type = months;
							where.qorder_year = years;
							where.ajax = 1;
						$.get('index.html', where, function(data){
							$("#ajaxDiv").html(data);
						});
					});
				}else{
					layer.msg('无账单生成', {icon: 2, time: 2000});
				}
			});
		});
		
		//账单审核
		$(".report").on('click', function(){
			var ids = '';
			$("tr.text-c td input:checkbox").each(function(){
				if($(this).is(":checked")){
					ids += $(this).val()+',';
				}
			});

			if(ids.length <= 0){
				layer.msg('请选择需要审核的账单', {icon: 5, time: 2000});
				return false;
			}
			//重新获取数据
			$.post('report.html', {ids: ids, status: $("#allstatus").val()}, function(row){
				if(row/1){
					layer.msg('审核成功', {icon: 1, time: 2000}, function(){
						var load = layer.load(2);
						var where = {};
							//where.page = {$page};
							where.room_number = $("#room_number").val();
							where.order_type = $("#order_type").val();
							where.status = $("#status").val();
							where.qorder_type = $("#qorder_type").val();
							where.qorder_year = $("#qorder_year").val();
							where.ajax = 1;
						$.get('index.html', where, function(data){
							layer.close(load);
							$("#ajaxDiv").html(data);
						});
					});
				}else{
					layer.msg('审核失败', {icon: 2, time: 2000});
				}
			});
		});
		
		//导出数据
		$(".explodes").on('click', function(){
			var room_number = $("#room_number").val();
			var order_type = $("#order_type").val();
			var status = $("#status").val();
			var qorder_type = $("#qorder_type").val();
			var qorder_year = $("#qorder_year").val();

			location.href = 'explodes.html?room_number='+ room_number + '&order_type='+ order_type + '&status='+ status + '&qorder_type='+ qorder_type + '&qorder_year='+ qorder_year;
		});
	});
	
	/*管理员-角色-添加*/
	function admin_role_add(title,url,w,h){
		layer_show(title,url,w,h);
	}
	
	/*管理员-角色-编辑*/
	function admin_role_edit(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
	
	function admin_role_del(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			$.post('index.html', {tid: id}, function(rs){
				if(rs == '删除成功'){
					$("#tr_"+ id).html('是');
				}

				layer.msg(rs, {icon:1,time: 2000});
			});
		});
	}
</script>
</body>
</html>